package com.itheima.tliasmanager.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.tliasmanager.exception.DeptNotAllowedDeleteException;
import com.itheima.tliasmanager.mapper.DeptMapper;
import com.itheima.tliasmanager.mapper.EmpMapper;
import com.itheima.tliasmanager.pojo.domain.Dept;
import com.itheima.tliasmanager.pojo.domain.Emp;
import com.itheima.tliasmanager.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 部门表 服务实现类
 * </p>
 *
 * @author sx
 * @since 2025-09-08
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements IDeptService {


    @Autowired
    private EmpMapper empMapper;

    @Override
    public void removeByDeptId(Integer id) {
        List<Emp> emps = empMapper.selectList(new LambdaQueryWrapper<Emp>().eq(Emp::getDeptId, id));
        if(emps != null && emps.size() > 0){
            throw new DeptNotAllowedDeleteException("此部门下有员工，不能进行删除操作！");
        }

        removeById( id );

    }
}
